﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zor_DAL;
using Zor_Tools;

namespace Zor_Bll
{
    public class LeaseBrowse_Bll<T> where T : class
    {
        /// <summary>
        /// 获取租赁信息列表
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="TotalCount">返回值</param>
        /// <returns></returns>
        public static List<T> GetPageList(dynamic Model, int index, out int TotalCount,string where)
        {
            int Dtid = RequestSession.GetSessionUser().DT_Id;
            int Isadmin = RequestSession.GetSessionUser().Is_Admin;
            var sqlSurch = " 1=1 ";
            if (Isadmin == 1 || Dtid == 16)
            {
                sqlSurch = " 1=1 ";
            }
            else
            {
                sqlSurch = " (StreetOfficeID = " + Dtid + "  or Dt_ParentId = " + Dtid + ") ";
            }          
            if (Model.StreetOffice != null)
            {
                sqlSurch += " and " + " StreetOffice like '%" + Model.StreetOffice + "%'  ";
            }
            if (Model.Community != null)
            {
                sqlSurch += " and " + " Community like '%" + Model.Community + "%'  ";
            }
            if (Model.NatPer_Name != null)
            {
                sqlSurch += " and " + " NatPer_Name like '%" + Model.NatPer_Name + "%'  ";
            }
            if (Model.Tenant_Name != null)
            {
                sqlSurch += " and " + " Tenant_Name like '%" + Model.Tenant_Name + "%'  ";
            }
            if (Model.Lease_StartTime != null && Model.Lease_EndTime == null)
            {
                int StartTime = TimeHelper.ToTimeStamp(DateTime.Parse(Model.Lease_StartTime.ToString()));
                sqlSurch += " and " + " Lease_StartTime = '" + StartTime + "'  ";
            }
            if (Model.Lease_EndTime != null && Model.Lease_StartTime == null)
            {
                int EndTime = TimeHelper.ToTimeStamp(DateTime.Parse(Model.Lease_EndTime.ToString()));
                sqlSurch += " and " + " Lease_EndTime = '" + EndTime + "'  ";
            }
            if (Model.Lease_EndTime != null && Model.Lease_StartTime != null)
            {
                int StartTime = TimeHelper.ToTimeStamp(DateTime.Parse(Model.Lease_StartTime.ToString()));
                int EndTime = TimeHelper.ToTimeStamp(DateTime.Parse(Model.Lease_EndTime.ToString()));
                sqlSurch += " and " + " Lease_StartTime between '" + StartTime + "' and '" + EndTime + "'  ";
            }
            if (Model.Statue != null)
            {
                if (Model.Statue == "全部")
                {
                    sqlSurch += " and " + " Statue in('已过期','正常租赁') ";
                }
                else
                {
                    sqlSurch += " and " + " Statue = '" + Model.Statue + "'  ";
                }
             
            }
            return PagerHelp<T>.GetPagerList(index, "V_LeaseBrowse", "Community", out TotalCount, sqlSurch);
        }
    }
}
